//
//  MapBottomSingleButton.m
//  Trackit
//
//  Created by yaodaobin on 2017/4/13.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import "MapBottomSingleButton.h"

@implementation MapBottomSingleButton

- (instancetype)initWithFrame:(CGRect)frame image:(NSString *)string text:(NSString *)text {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI:string text:text];
    }
    return self;
}

- (void)initUI:(NSString *)string text:(NSString *)text {
    self.imageView = [[UIImageView alloc] init];
    self.imageView.image = [UIImage imageNamed:string];
    [self addSubview:self.imageView];
    
    self.label = [[UILabel alloc] init];
    self.label.text = text;
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.label];
    
    kWeakSelf
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(0);
        make.bottom.equalTo(weakSelf.label.mas_top).offset(-5);
    }];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.offset(0);
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
    [self addGestureRecognizer:tapGesture];

}

- (void)setImage:(NSString *)string text:(NSString *)text {
    self.imageView.image = [UIImage imageNamed:string];
    self.label.text = text;
}

#pragma mark - Action
- (void)viewTapped:(UITapGestureRecognizer *)ges {
    if (self.tapBlock) {
        self.tapBlock(self.tag);
    }
}


@end
